<?php
namespace app\admin\controller;
use think\facade\Db;
use think\facade\Request;

class Api extends  Base
{

    //友情链接列表
    public function index()
    {
      $apiData=Db::name('api')->paginate(15);
      return view('',[
         'apiData'=>$apiData,
         'left_menu'=>3
        ]);

    }

    /*添加*/
    public function add(){
       if(request()->isPost()){
         $data=request()->post();
         
     foreach ($data['data'] as $k=>$val){
$returnParameters[$k]['data'] = $data['data'][$k];
$returnParameters[$k]['String'] = $data['String'][$k];
$returnParameters[$k]['shuoming'] = $data['shuoming'][$k];
}
     foreach ($data['data1'] as $k=>$val){
$RequestParameters[$k]['data'] = $data['data1'][$k];
$RequestParameters[$k]['String'] = $data['String1'][$k];
$RequestParameters[$k]['bitian'] = $data['bitian'][$k];
$RequestParameters[$k]['shuoming'] = $data['shuoming1'][$k];
}
     foreach ($data['data2'] as $k=>$val){
$errorcode[$k]['data'] = $data['data2'][$k];
$errorcode[$k]['shuoming2'] = $data['shuoming2'][$k];
}
      foreach ($data['data3'] as $k=>$val){
$systemcode[$k]['data'] = $data['data3'][$k];
$systemcode[$k]['shuoming'] = $data['shuoming3'][$k];
}
$data['returnParameters']=json_encode($returnParameters);
$data['RequestParameters']=json_encode($RequestParameters);
$data['errorcode']=json_encode($errorcode);
$data['systemcode']=json_encode($systemcode);
       
         $res=Db::name('api')->insert($data);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
       }
       return view('',[
         'left_menu'=>3
        ]);
    }

    /*修改*/
    public function edit(){
        $id=input('id');
    $apiData=Db::name('api')->find($id);
    $returnParameters=json_decode($apiData['returnParameters'], true);
    $RequestParameters=json_decode($apiData['RequestParameters'], true);
    $errorcode=json_decode($apiData['errorcode'], true);
    $systemcode=json_decode($apiData['systemcode'], true);
      return view('',[
     'apiData'=>$apiData,
     'RequestParameters'=>$RequestParameters,
     'returnParameters'=>$returnParameters,
     'errorcode'=>$errorcode,
     'systemcode'=>$systemcode,
        ]);
        
        
        
    }
  public function delect(){
      $id=input('id');//助手函数
   
      $res=Db::name('api')->delete($id);
      if($res){
            return alert('删除成功!','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         } 
    }

    public function update(){
      //处理post过来的数据
       if(request()->isPost()){
         $data=request()->post();
         $res=Db::name('flink')->update($data);
         if($res){
            return alert('操作成功！','index',6,3);
         }else{
            return alert('操作失败！','index',5,3);
         }
       }
    }
    
    
}
